﻿$(function () {

    var hub = $.connection.guiGameHub;

    hub.client.hideCard = function (cardId)
    {
        var buttonThatWasClicked = $("#" + cardId);
        buttonThatWasClicked.children().css('visibility', 'hidden');
    };

    hub.client.hideActionCard = function (cardId)
    {
        var buttonThatWasClicked = $("#" + cardId);
        alert("HALLLO");
        buttonThatWasClicked.children().children().css('visibility', 'hidden');
    };

    hub.client.gameFinished = function (cardId, winner, scoreOfWinner)
    {

        $(function () {
            $("<div title='Leik lokið!'>" + winner + " vann með " + scoreOfWinner + " stigum!  </div>").dialog(
                {
                    buttons: {
                        Heim: function () {
                            window.location = '/Home';
                        }
                    }
                });
        });
    };

    hub.client.player2Turn = function ()
    {
        $("#YourTurn1").css('visibility', 'hidden');
        $("#YourTurn2").css('visibility', 'visible');

    };

    hub.client.player1Turn = function ()
    {
        $("#YourTurn1").css('visibility', 'visible');
        $("#YourTurn2").css('visibility', 'hidden');

    };

    hub.client.player1Starts = function ()
    {
        $("#YourTurn1").css('visibility', 'visible');
    };

    hub.client.player2Starts = function ()
    {
        $("#YourTurn2").css('visibility', 'visible');
    };

    hub.client.showUpdateScore = function (user1Score, user2Score)
    {

        document.getElementById("ScoreUser1").innerHTML = user1Score;
        document.getElementById("ScoreUser2").innerHTML = user2Score;
    };

    hub.client.showUserOne = function (user1)
    {

        document.getElementById("SUser1").innerHTML = user1;
    };

    hub.client.showUserTwo = function (user2)
    {

        document.getElementById("SUser2").innerHTML = user2;
    };

    hub.client.waitForUser2 = function ()
    {
        $(function ()
        {
            $("Beðið eftir því að fá mótspilara...").dialog(
                {

                });
        });
    };

    $.connection.hub.start().done(function ()
    {
        hub.server.join(group);
        hub.server.initialiseUsers(group);

        $(".NobelButton").click(function ()
        {
            hub.server.clickedNobel(user, group, this.id);
        });

        $(".ActButton").click(function ()
        {
            hub.server.clickedAction(user, group, this.id);
        });
    });
});
